using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace AppToolKit.Core.Utils.Security
{
	public class CryptoUtil
	{
		private byte[] key_;
		private byte[] iv_;
		public byte[] Key
		{
			get
			{
				return this.key_;
			}
		}
		public byte[] IV
		{
			get
			{
				return this.iv_;
			}
		}
		public CryptoUtil(byte[] iv, byte[] key)
		{
			this.iv_ = iv;
			this.key_ = key;
		}
		public string Decode(string s)
		{
			DES dES = new DESCryptoServiceProvider();
			dES.Key = this.Key;
			dES.IV = this.IV;
			byte[] array = null;
			string result;
			try
			{
				array = Convert.FromBase64String(s);
			}
			catch
			{
				result = string.Empty;
				return result;
			}
			MemoryStream memoryStream = new MemoryStream();
			CryptoStream cryptoStream = new CryptoStream(memoryStream, dES.CreateDecryptor(), CryptoStreamMode.Write);
			cryptoStream.Write(array, 0, array.Length);
			cryptoStream.Flush();
			cryptoStream.FlushFinalBlock();
			string @string = Encoding.UTF8.GetString(memoryStream.ToArray());
			dES.Clear();
			dES = null;
			result = @string;
			return result;
		}
		public string Encode(string s)
		{
			DES dES = new DESCryptoServiceProvider();
			dES.Key = this.Key;
			dES.IV = this.IV;
			MemoryStream memoryStream = new MemoryStream();
			CryptoStream cryptoStream = new CryptoStream(memoryStream, dES.CreateEncryptor(), CryptoStreamMode.Write);
			byte[] bytes = Encoding.UTF8.GetBytes(s);
			cryptoStream.Write(bytes, 0, bytes.Length);
			cryptoStream.Flush();
			cryptoStream.FlushFinalBlock();
			string result = Convert.ToBase64String(memoryStream.ToArray());
			dES.Clear();
			return result;
		}
	}
}
